package com.rsscollector.model.vo;

import javax.persistence.*;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;

@Entity
@Table(name = "RSS_SOURCE")
public class RssSource implements Serializable {

    private Long id;

    private String title;

    private String rssUrl;

    private RssProvider provider;

    private Collection<Category> categories = new HashSet<Category>();

    private Collection<RssContent> rssContent = new HashSet<RssContent>();

    private Date lastUpdate = new Date();

    private boolean active;

    // No-arg constructor
    public RssSource() {
        this.active = true;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "RSS_SOURCE_ID")
    public Long getId() {
        return this.id;
    }

    protected void setId(Long id) {
        this.id = id;
    }

    @Column(name = "TITLE", nullable = true, length = 200)
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "RSS_URL", nullable = false, length = 200)
    public String getRssUrl() {
        return this.rssUrl;
    }

    public void setRssUrl(String rssUrl) {
        this.rssUrl = rssUrl;
    }

    @ManyToOne()
    @JoinColumn(name = "RSS_PROVIDER_ID", nullable = true)
    public RssProvider getRssProvider() {
        return this.provider;
    }

    public void setRssProvider(RssProvider provider) {
        this.provider = provider;
    }

    @ManyToMany(mappedBy="rssSources")
    public Collection<Category> getCategories() {
        return this.categories;
    }

    public void setCategories(Collection<Category> categories) {
        this.categories = categories;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rssSource")
    public Collection<RssContent> getRssContents() {
        return this.rssContent;
    }

    public void setRssContents(Collection<RssContent> rssContent) {
        this.rssContent = rssContent;
    }

    @Column(name = "LAST_UPDATE", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)    
    public Date getLastUpdate() {
        return this.lastUpdate;
    }

    public void setLastUpdate(Date date) {
        this.lastUpdate = date;
    }
    @Column(name = "ACTIVE_FLAG", nullable = true)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
}
